#!/usr/bin/env python

# Author                 Version      Up-Date
# -----------------------------------------------
# L. Fraga (SOAR)          1.0        29 Sep 2009
# Mosaic the  extensions of the SOAR Optical Imager
# Made by Eduardo S. Cypriano (Jan-2005) La Serena, Chile based on GMOSAIC
# Correction in task geotran (Alexandre Oliveira, 14/07/2006).
# Translated to PyRAF by L. Fraga (Sep 2007)

from pyraf import iraf
from iraf import pysoar
from iraf import soi
import pysoarlib as lib
import soarprint
from mosaic import mosaic

def soimosaic(input,output,logfile,verbose):

        infiles  = iraf.files(input,Stdout=1)
        outfiles = iraf.files(output,Stdout=1)

        lib.comparelists(infiles,outfiles,'infiles','outfiles')
        
        #TODO: check if the image is single or MEF fits
        for i in range(len(infiles)):
                message = 'MESSAGE -- SOIMOSAIC: WORKING ON IMAGE %s'%(infiles[i])
                soarprint.log(logfile,message,verbose)           
                try:
                        mosaic(infiles[i],outfiles[i])
                except:
                        message = 'ERROR -- SOIREDUCE.MOSAIC: IN FILE %s'%(infiles[i])
                        soarprint.err(logfile,message)           
parfile = iraf.osfn("pysoar$soi/soimosaic.par")
t = iraf.IrafTaskFactory(taskname="soimosaic",value=parfile,function=soimosaic)
